package com.qf.controller;

import com.qf.pojo.ListUser;
import com.qf.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

//该类是个controller 控制器
@Controller
public class HelloController {
    @RequestMapping("/test1")
    public void test1() {
        System.out.println("这是我MVC的第一个接受请求的方法");
    }

    /*
     *  接受8大基本类型 + String + Date
     *    http://localhost:8080/test2?id=1&name=zhangsan&salary=350.5&birth=2020-06-01
     * */
    @RequestMapping("/test2")
    public void test2(Integer id, String name, Double salary, @DateTimeFormat(pattern = "YYYY-MM-dd") Date birth) {
        System.out.println("id = " + id + ", name = " + name + ", salary = " + salary + ", birth = " + birth);
    }

    /*
     * 接受实体对象
     *  http://localhost:8080/test3?id=1&name=zhangsan&salary=350.5&birth=2020-06-01
     * */
    @RequestMapping("/test3")
    public void test3(User user) {
        System.out.println("test3" + user + "000");
    }

    /*
     *
     *  http://localhost:8080/test4?hobby=lang&hobby=jump
     * */
    @RequestMapping("/test4")
    public void test4(String[] hobby) {
        for (String h : hobby) {
            System.out.println(h);
        }
    }

    /*
     *
     * 集合收参
     * */
    @RequestMapping("/test5")
    public void test5(ListUser listUser) {
        listUser.getUser().forEach(System.out::println);
    }

    /*
     * 路径收参  不在用？ 分割  和 key=value 的形式传值
     * http://localhost:8080/test6/10 此刻的10 是ID
     * */
    @RequestMapping("/test6/{id}")
    public void test6(@PathVariable Integer id) {
        System.out.println(id);
    }

    @RequestMapping("/test7/{id}/{name}")
    public void test7(@PathVariable Integer id, @PathVariable("name") String name) {
        System.out.println(id + "wwww" + name);
    }


}
